10 REM TIC-TAC-TOE
20 DIM B$(9), V(9)
30 LET V(1)=8: LET V(2)=1: LET V(3)=6
40 LET V(4)=3: LET V(5)=5: LET V(6)=7
50 LET V(7)=4: LET V(8)=9: LET V(9)=2
60 PRINT "WELCOME TO TIC-TAC-TOE"
70 PRINT "YOU ARE 'X'.  PRESS <CTRL+BREAK> TO STOP": GOTO 110
90 REM NEW GAME
100 PRINT "": PRINT "TRY AGAIN": PRINT ""
110 LET F=0: FOR I=1 TO 9: LET B$(I)=" ": NEXT I
120 REM PRINT BOARD
130 PRINT "        COLUMNS"
140 PRINT "       1   2   3"
150 PRINT "ROW 1  ";B$(1);" | ";B$(2);" | ";B$(3)
160 PRINT "       --+---+--"
170 PRINT "    2  ";B$(4);" | ";B$(5);" | ";B$(6)
180 PRINT "       --+---+--"
190 PRINT "    3  ";B$(7);" | ";B$(8);" | ";B$(9)
200 PRINT "": IF F<9 THEN GOTO 220
210 PRINT "I WIN!!": GOTO 90
220 IF F<5 THEN GOTO 250
235 PRINT "TIE GAME": GOTO 90
250 REM GET MOVE
260 PRINT "ENTER ROW & COLUMN OF YOUR MOVE": INPUT I,J
270 IF I<1 OR I>3 OR J<1 OR J>3 THEN GOTO 250
280 LET K=I+I+I+J-3: IF B$(K)=" " THEN GOTO 300
290 PRINT "THAT BOX HAS A '";B$(K);"' IN IT.": GOTO 250
300 LET B$(K)="X": LET F=F+1: IF F=5 THEN GOTO 120
310 IF F<2 THEN GOTO 450
320 REM MAGIC
330 LET P=0: FOR I=1 TO 8: 
335    FOR J=I+1 TO 9
340      IF B$(I)=" " OR B$(I)<>B$(J) THEN GOTO 400
350      LET K=V(I)+V(J)-5: IF K<1 OR K>9 THEN GOTO 400
360      LET K=V(K): IF B$(K)<>" " THEN GOTO 400
370      IF B$(I)="X" THEN GOTO 390
380      LET B$(K)="O": LET F=9: GOTO 120
390      LET P=K
400    NEXT J: 
402 NEXT I: IF P=0 THEN GOTO 450
410 LET B$(P)="O": GOTO 120
450 REM CHOOSE AN UNFORCED MOVE
460 IF B$(5)<>" " THEN GOTO 480
470 LET B$(5)="O": GOTO 120
480 LET P=1: IF B$(5)="X" THEN GOTO 500
490 LET P=2
500 FOR I=P TO 9 STEP 2
510 IF B$(I)<>" " THEN GOTO 530
520 LET B$(I)="O": GOTO 120
530 NEXT I
540 FOR I=7+P TO 1 STEP -2
550 IF B$(I)<>" " THEN GOTO 570
560 LET B$(I)="O": GOTO 120
570 NEXT I
580 END
